/**
 * Created by miaoyu on 2017/7/20.
 */
function showButtons() {
    var params =decodeURIComponent(window.location.search.substr(1)).split('&');
    var postID =(params[0].split('='))[1];
    var page = (params[1].split('='))[1];
    var xmlhttp;
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
            document.getElementById("pager").innerHTML = xmlhttp.responseText;
            document.getElementById("topBtns").innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","innerPostButton.jsp?postID="+postID+"&destination=innerPost&currentNum="+page,true);
    xmlhttp.send();
}


function toPostPage(num) {
    var params =decodeURIComponent(window.location.search.substr(1)).split('&');
    var postID =(params[0].split('='))[1];
    window.location.href = "innerPost.jsp?postID=" + postID+"&page="+ num;
}

function lastPage() {
    var params =decodeURIComponent(window.location.search.substr(1)).split('&');
    var postID =(params[0].split('='))[1];
    var page = (params[1].split('='))[1];
    var num = page-1;
    window.location.href = "innerPost.jsp?postID=" + postID+"&page="+ num;
}

function nextPage() {
    var params =decodeURIComponent(window.location.search.substr(1)).split('&');
    var postID =(params[0].split('='))[1];
    var page = (params[1].split('='))[1];
    var num = parseInt(page)+1;
    window.location.href = "innerPost.jsp?postID=" + postID+"&page="+ num;
}

function jumpTo(btn) {
    var params =decodeURIComponent(window.location.search.substr(1)).split('&');
    var postID =(params[0].split('='))[1];
    var min = 1;
    var num = parseInt(btn.parentNode.childNodes.item(btn.parentNode.childNodes.length-4).value);
    var max = parseInt(btn.name);
    if(num<min||num>max){

    }else {
        window.location.href = "innerPost.jsp?postID=" + postID+"&page="+ num;
    }

}



function showReplyForm(btn) {
    var btnID = btn.id;
    var num = btnID.substring(8);
    var formID = "replyForm" + num;
    var form = document.getElementById(formID);
    // var forms = document.getElementsByClassName("replyForm");

    //forms.style.display = "none";
    var state = form.style.display;
    if (state === "block"){
        form.style.display="none";
        btn.value = "回复";
    }else if (state === "none"){
        form.style.display="block";
        btn.value = "取消回复";
    }

}

function reply(btn) {
    var params =decodeURIComponent(window.location.search.substr(1)).split('&');
    var postID =(params[0].split('='))[1];
    var floorID = btn.id.substring(11);
    var inputID = "replyInput" +floorID;
    var input = document.getElementById(inputID);
    var content = input.value;
    window.location.href = "ReplyServlet?content=" + content+"&floorID="+floorID +"&postID="+postID;
}